// import Cookies from 'js-cookie'
import crypto from 'crypto'
import MD5 from 'js-md5'

// const TokenKey = 'token'

// export function getToken () {
//   return Cookies.get(TokenKey)
// }

// export function setToken (token) {
//   return Cookies.set(TokenKey, token.substr(0, 10))
// }

// export function removeToken () {
//   window.loadAsyncRoute = null
//   localStorage.removeItem('vuex')
//   return Cookies.remove(TokenKey)
// }

export function encrypt (type, secret) {
  if (!secret) return
  let result = ''
  switch (type) {
    case 'md5':
      result = MD5(secret)
      break
    default:
      break
  }
  return result
}

export function cipher (buf) {
  let encrypted = ''
  let cip = crypto.createCipher('aes192', 'fe-car-yooli')
  encrypted += cip.update(buf, 'utf8', 'hex')
  encrypted += cip.final('hex')
  return encrypted
}

export function decipher (encrypted) {
  let decrypted = ''
  let decip = crypto.createDecipher('aes192', 'fe-car-yooli')
  decrypted += decip.update(encrypted, 'hex', 'utf8')
  decrypted += decip.final('utf8')
  return decrypted
}
